﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DIS_WEB_Client.ViewModels.GroupViewModel>" %>
<script type="text/javascript">
    $(function () {
        // Document.ready -> link up remove event handler 
        $(".RemoveLink").click(function () {
            // Get the id from the link 
            var recordToDelete = $(this).attr("data-id");

            if (recordToDelete != '') {

                // Perform the ajax post 
                $.post("/Home/RemoveFromCart", { "id": recordToDelete },
                function (data) {
                    // Successful requests get here 
                    // Update the page elements 
                    $('#row-' + data.DeleteId).fadeOut('slow');
                    $('#cart-total').text(data.CartTotal + " USD");
                });
            }
        });

    });

    function handleUpdate() {
        // Load and deserialize the returned JSON data 
        var json = context.get_data();
        var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);

        // Update the page elements 
        $('#row-' + data.DeleteId).fadeOut('slow');
        $('#cart-total').text(data.CartTotal + " USD");
    }
</script> 

<div style="clear:both"><img src="../../../Content/Images/RHS_Top.jpg" width="300" height="45" alt="Shop Online Now!"></div>
        <div id="RHS_WaysToShop">
            <div class="container">              
                <div style="clear:both"><img src="../../../Content/Images/horz_sep.png" width="280" height="1" class="horz_div"></div>
                <div>
                    <div class="pointer"></div>
                    <div class="text">
                        <div>
                            <div style="float:left"><a href="http://www.chemistwarehouse.com.au/cartedit.asp" style="color:#6d6e71">Your Shopping Cart / Checkout</a></div>
                            <div style="float:left; padding-left:5px"><a href="http://www.chemistwarehouse.com.au/cartedit.asp"><img src="../../../Content/Images/cart_img.png" alt="View Your Cart / Check Out" title="View Your Cart / Check Out"></a></div>
                        </div>
                        <!--DYNSTART-->
                        
                        <div id="cart_section_top" style="clear:both;">
                            <table border="0" width="100%" cellspacing="0" cellpadding="0">
                                <% 
                                    var cartIsEmpty = true;
                                    if (Model.ShoppingCartModel != null && Model.ShoppingCartModel.CartItems != null && Model.ShoppingCartModel.CartItems.Count > 0)
                                    {
                                        cartIsEmpty = false;
                                    } 
                                %>
                                <% if (cartIsEmpty)
                                    { %>
                                    <tr>
                                        <td>
                                            <center style="color:Blue;">Your cart is empty!</center>
                                        </td>
                                    </tr>
                                <% }
                                    else
                                    { %>
                                    <tr style="border-top: 1px dotted #ddd;">
                                        <td colspan="4" style="height:5px;"></td>
                                    </tr>
                                    <% for (int i = 0; i < Model.ShoppingCartModel.CartItems.Count; i++ )
                                        { %>
                                        <tr id="row-<%= Model.ShoppingCartModel.CartItems[i].RecordId %>"> 
                                            <td style="text-align:left;">
                                                <%
                                                    var item = Model.AllItemModel.GetModel.LstObjModel.FirstOrDefault(n => n.ID == Model.ShoppingCartModel.CartItems[i].ItemID);
                                                    %>
                                                <%= i+1 %> - <%= item.Name%>
                                            </td>
                                            <td style="width:20px; text-align:center; padding-left: 5px;">
                                                <script type="text/javascript">
                                                    function ReCalcOrder(itemid, idcate) {
                                                        var num = document.getElementsByName("NumItem" + itemid).item(0);
                                                        window.location.href = "../Home/AddToCart?id=" + itemid + "&idcate=" + idcate + "&num=" + num.value;
                                                    }
                                                </script>
                                                <input type="text" name="NumItem<%= item.ID %>" id="item-count-<%= Model.ShoppingCartModel.CartItems[i].RecordId %>" value="<%= Model.ShoppingCartModel.CartItems[i].Count %>" style="width:15px;font-size:10px;text-align:center;" maxlength="2" onkeyup='ReCalcOrder(<%= item.ID %>, <%= item.IDCategory %>);'>
                                            </td>
                                            <td style="width:70px;text-align:right;padding-right:15px;"><%= CommonHelpers.CalcPromotionPrice(item) %> USD</td>
                                            <td style="width:12px;">
                                                <a href="#" title="Remove from cart" class="RemoveLink" data-id="<%= Model.ShoppingCartModel.CartItems[i].RecordId %>">
                                                    <img src="../../../Content/Images/delete.gif" alt="Remove From Cart" border="0" />
                                                </a>
                                            </td>
                                        </tr>
                                    <% } %>
                                    <tr style="border-top: 1px dotted #ddd;">
                                        <td style="padding-left: 4px; padding-top: 15px;">Total amount</td>
                                        <td id="cart-total" colspan="2" style="text-align:right;padding-right:15px;font-weight:bold;  padding-top: 15px;">
                                            <%= Model.ShoppingCartModel.CartTotal %> USD
                                        </td>
                                        <td style="padding-top: 15px;">
                                            <a href="#" title="Empty Cart">
                                            </a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="4" style="height:10px;"></td>
                                    </tr>
                                    <tr>
                                        <td colspan="4" align="center">
                                            <% using (Html.BeginForm("Approve", "Home", FormMethod.Post))
                                                { %>
                                                <p style="text-align:center; margin-bottom: 5px;">
                                                    <input name="totalpay" type="hidden" value="<%= Model.ShoppingCartModel.CartTotal %>" />
                                                    <input type="submit" name="sbt" id="sbt" value="Continue to checkout" style="background-image: url(../../../Content/Images/bgbutton.jpg); color: #FFFFFF; font-size: 16px; font-weight: bold; border: 1px #DBDBDB solid; height: 30px; cursor:pointer;" />
                                                </p>
                                            <% } %>
                                        </td>
                                    </tr>
                                <% } %>
                            </table><!-- End   - put your content here --->
                        </div>
                        <!--DYNEND-->
                    </div>
                </div>
                <!--DYNSTART-->
                <div style="clear:both"><img src="../../../Content/Images/horz_sep.png" width="280" height="1" class="horz_div"></div>
                
                <div>
                    <div class="pointer"></div>
                    <div class="text">
                        <div style="clear:both">
                            <!-- User has loged in -->
                            <% if (WebConfiguration.IsRequestAuthentication)
                               { %>
                                <div style="float:left">
                                    <a href="<%= Url.Action("Logout", "Home") %>" id="A1">Logout</a>
                                </div>
                                <% if (WebConfiguration.AllowAccessAdminCP)
                                   { %>
                                    <div style="float:left; padding: 0 5px 0 5px">|</div>
                                <% }
                                   else
                                   { %>
                                    <div style="float:left; padding: 0 5px 0 5px">|</div>
                                <% } %>
                                <div style="float:left">
                                    <%
                                        HttpCookie SlmMemberCookie = new HttpCookie("SLMFMembers");
                                        SlmMemberCookie = HttpContext.Current.Request.Cookies["SLMFMembers"];
                                        string strUser = string.Empty;
                                        if (SlmMemberCookie != null && SlmMemberCookie.Value != "" &&
                                             SlmMemberCookie.Value != null)
                                        {
                                            strUser = SlmMemberCookie.Value.ToString();
                                        }
                                    %>
                                    <a href="<%= Url.Action("AccountInfo", "Home", new { username = strUser }) %>" id="A2">Your Account</a>
                                </div>
                            <% if (WebConfiguration.AllowAccessAdminCP)
                               { %>
                                <div style="float:left; padding: 0 5px 0 5px">|</div>
                                <div style="float:left">
                                    <a href="<%= Url.Action("Index", "Admin") %>" id="A3">Admin Page</a>
                                </div>
                            <% }
                               else
                               { %>
                                <div style="float:left; padding: 0 5px 0 5px">|</div>
                                <div style="float:left">
                                    <a href="<%= Url.Action("OrdersHistory", "Home", new { username = strUser }) %>" id="A4">Orders History</a>
                                </div>
                            <% } %>
                            <% }
                               else
                               { %>
                                <div style="float:left">
                                    <a href="<%= Url.Action("Login", "Home") %>" id="loginOrLogoutLink">Login</a>
                                </div>
                                <div style="float:left; padding: 0 30px 0 30px">|</div>
                                <div style="float:left">
                                    <a href="<%= Url.Action("Register", "Home") %>" id="NewRegistLink">Register Here</a>
                                </div>
                            <% } %>
                        </div>
                    </div>
                </div>
                <!--DYNEND-->
            </div>
        </div>